package com.caac.core.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caac.core.Global;
import com.caac.core.util.HttpUtils;
import com.caac.core.web.form.BaseForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright caac 2004</p>
 * <p>Company: caac</p>
 * @author <a href="mailto:project@caac.com.cn">Project Group</a>
 * @version 1.0
 */

public abstract class BaseViewAction extends BaseAction {
    protected final ActionForward doExecute(ActionMapping mapping,
                                            BaseForm form,
                                            HttpServletRequest request,
                                            HttpServletResponse response) throws
            Exception {
        ViewForward vf = doViewExecute(mapping, form, request, response);
        HttpUtils.setAttribute(request, Global.KEY_DATA, vf.getData());
        HttpUtils.setAttribute(request, Global.KEY_VIEW_NAME, vf.getViewName());
        HttpUtils.setAttribute(request, Global.KEY_VIEW_PROPS, vf.getViewProps());
        return vf.getFoward();
    }

    protected abstract ViewForward doViewExecute(ActionMapping mapping,
                                                 BaseForm form,
                                                 HttpServletRequest request,
                                                 HttpServletResponse response) throws
            Exception;
}
